package org.example.cloudcommon.async.demo;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Order(0)
public class CustomAsyncAspect {
    @Autowired
    private TaskExecutor taskExecutor;

  //  @Pointcut("execution(* com.wz.blog.*.*(..))")指定拦截com.wz.blog包下所有类的所有方法

    @Pointcut("@annotation(org.example.cloudcommon.async.demo.CustomAsync)")
    private void pointcut() {
    }


    @Around("pointcut()")
    public Object handleCustomAsyncMethodAround(ProceedingJoinPoint joinPoint) {
        taskExecutor.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    joinPoint.proceed();
                } catch (Throwable e) {
                    throw new RuntimeException(e);
                }
            }
        });
        return null;
    }
}
